package com.cssiot.weixin.basic.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.cssiot.weixin.basic.data.WeixinContext;
import com.cssiot.weixin.basic.task.RefreshAccessTokenTask;

/**
 * 初始化servlet
 * @author jacking
 *
 */
public class InitServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;
	private static WebApplicationContext wc;
	private static String realpath;
	
	@Override
	public void init(ServletConfig config) throws ServletException {
		super.init(config);
		//初始化spring的工厂
		wc = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
		realpath = config.getServletContext().getRealPath("");
//		RefreshAccessTokenTask refreshAccessTokenTask = (RefreshAccessTokenTask) wc.getBean("refreshAccessTokenTask");
		
		//	WeixinContext.setAccessToken
		
//		refreshAccessTokenTask.refreshToken();
		System.out.println("初始化获取的access_token:"+WeixinContext.getAccessToken());
		BeanFactoryContext.setWc(wc);
	}
	
	public static String getRealpath() {
		return realpath;
	}
	
	public static WebApplicationContext getWc() {
		return wc;
	}

}